<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class tire_tread_wear_list extends Page
{
       public $lblTimesRecapped = null;
       public $Label7 = null;
       public $hfMounted = null;
       public $imgRecap = null;
       public $JTDivInfo = null;
       public $JTGroupBox5 = null;
       public $Label13 = null;
       public $imgInfo = null;
       public $JTJavaScript1 = null;
       public $btnExport = null;
       public $lblPosition = null;
       public $lblMounted = null;
       public $lblManufacturer = null;
       public $lblRecap = null;
       public $lblBranding = null;
       public $lblSerial = null;
       public $Label6 = null;
       public $Label5 = null;
       public $Label4 = null;
       public $Label3 = null;
       public $Label2 = null;
       public $Label1 = null;
       public $delete = null;
       public $Image1 = null;
       public $imgAdd = null;
       public $imgBack = null;
       public $hfTireId = null;
       public $JTTreadWearList = null;
       public $JTSiteTheme1 = null;
       function imgRecapJSClick($sender, $params)
       {

       ?>
       var tire_id = document.getElementById('hfTireId').value;
       window.open("tire_tread_wear_recap.php?tire_id="+tire_id,"Window1","menubar=no,width=250,height=200,left=450,top=250,toolbar=no");
       <?php

       }

       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }

       function btnExportJSClick($sender, $params)
       {

       ?>
       var tire_id = document.getElementById('hfTireId').value;
       window.open("tire_tread_wear_excel.php?tire_id="+tire_id,"Window1","menubar=no,width=430,height=360,left=450,top=250,toolbar=no");
       <?php

       }


       function btnExportJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnExport'].src="image/excel.png"
       <?php

       }

       function btnExportJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnExport'].src="image/excel2.png"
       <?php

       }

       function imgAddJSClick($sender, $params)
       {
       ?>
       var mounted = document.getElementById('hfMounted').value;
       if(mounted==1)
       {
       var tire_id = document.getElementById('hfTireId').value;
       window.open("tire_tread_wear_create.php?tire_id="+tire_id,"Window1","menubar=no,width=500,height=250,left=450,top=250,toolbar=no");
       }
       if(mounted==0)
       {
        alert("Tire not mounted!");
       }
       //document.location.href = 'tire_tread_wear_create.php?tire_id='+tire_id;
       <?php
       }

       function imgRecapJSMouseOut($sender, $params)
       {
       ?>
       document.images['imgRecap'].src="image/recap.png"
       <?php
       }

       function imgRecapJSMouseOver($sender, $params)
       {
       ?>
       document.images['imgRecap'].src="image/recap2.png"
       <?php
       }

       function imgAddJSMouseOut($sender, $params)
       {
       ?>
       document.images['imgAdd'].src="image/add_new.png"
       <?php
       }

       function imgAddJSMouseOver($sender, $params)
       {
       ?>
       document.images['imgAdd'].src="image/add_new_blue.png"
       <?php
       }
       function imgBackJSClick($sender, $params)
       {
       ?>
       document.location.href = 'tire_list.php';
       <?php
       }

       function imgBackJSMouseOver($sender, $params)
       {
       ?>
       document.images['imgBack'].src="image/btn_back2.png"
       <?php
       }

       function imgBackJSMouseOut($sender, $params)
       {
       ?>
       document.images['imgBack'].src="image/btn_back.png"
       <?php
       }

       function tire_tread_wear_listCreate($sender, $params)
       {
       $get_tire_id = $_GET['tire_id'];
       if($get_tire_id!='' && $get_tire_id!=null && isset($get_tire_id))
       $this->hfTireId->setValue($get_tire_id);

       if($_SESSION['access_tire']==1)
       {
       $this->imgAdd->Visible=false;
       $this->btnExport->Left='960';
       }

       if($_SESSION['access_tire']==2)
       {
       $this->imgAdd->Visible=true;
       $this->btnExport->Left='856';
       }

       $query_tire = "SELECT times_recap,tire_SN, branding, recap, manufacturer, mounted_on, mounted_post FROM tire_inventory_tbl WHERE tire_id='".$this->hfTireId->getValue()."'";
       $result_tire = mysql_query($query_tire) or die("SELECT TIRE ".mysql_error());
       $row_tire = mysql_fetch_array($result_tire);

       $serial = $row_tire['tire_SN'];
       $branding = $row_tire['branding'];
       $recap = $row_tire['recap'];
       $manufacturer = $row_tire['manufacturer'];
       $veh_mount_id = $row_tire['mounted_on'];
       $post = $row_tire['mounted_post'];

       $query_plate = "SELECT veh_num FROM vehicle_tbl WHERE vehicle_id='".$veh_mount_id."'";
       $result_plate = mysql_query($query_plate) or die("SELECT TIRE ".mysql_error());
       $row_plate = mysql_fetch_array($result_plate);

       $mounted_on = $row_plate['veh_num'];
       if($mounted_on=='' || $mounted_on==null)
       {
        $this->hfMounted->setValue(0);
       }
       if($mounted_on!='' && $mounted_on!=null)
       {
        $this->hfMounted->setValue(1);
       }

       $this->lblSerial->Caption = $serial;
       $this->lblBranding->Caption = $branding;
       $this->lblRecap->Caption = $recap;
       $this->lblManufacturer->Caption = $manufacturer;
       $this->lblMounted->Caption = $mounted_on;
       $this->lblPosition->Caption = $post;
       $this->lblTimesRecapped->Caption = $row_tire["times_recap"];
       }

       function JTTreadWearListShow($sender, $params)
       {
       $tire_id = $this->hfTireId->getValue();
       $query_select = "SELECT * FROM tire_tread_wear_tbl WHERE tire_id='".$tire_id."' ORDER BY id DESC";
       $result_select = mysql_query($query_select) or die("SELECT ".mysql_error());
       $grid_arr = array();

       while($row_sel = mysql_fetch_array($result_select))
       {
        $id = $row_sel['id'];
        $date = $row_sel['insert_date'];
        $veh_mount = $row_sel['mounted_on'];
        $mount_post = $row_sel['mounted_post'];
        $query_plate = "SELECT veh_num FROM vehicle_tbl WHERE vehicle_id='".$veh_mount."'";
        $result_plate = mysql_query($query_plate) or die("SELECT PLATE NUM ".mysql_error());
        $row_plate = mysql_fetch_array($result_plate);


        if($veh_mount==0 || is_nan($veh_mount))
        {
        $plate = "<span style='color:red'>Not Mounted</span>";
        $post = '';
        $mount_string = "<span style='color:red'>Not Mounted</span>";
        }
        else
        {
        $plate = $row_plate['veh_num'];
        $post = $mount_post;
        $mount_string = "Mounted on ".$mount_post." of vehicle:".$plate;
        }

        //$edit_date = "<a href='tire_tread_wear_edit.php?id=".$id."'>".$date."</a>";



        $tools = "<img onclick=js_delete('".$id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";

        $edit_date = "<span onclick=openEditTread(".$id."); style='color:blue; cursor:pointer; text-decoration: underline;'>".$date."</span>";
        $edit_date = $date;

        if($_SESSION['access_tire']==1)
        {
        $grid_arr[] = array(
        'Date' => $edit_date,
        'Vehicle' => $plate,
        'Position' => $post,
        'Tread Depth' => $row_sel['tread'],
        'Pressure' => $row_sel['pressure'],
        'Km/Hrs' => $row_sel['kmrun']
        );
        }

        if($_SESSION['access_tire']==2)
        {
        $grid_arr[] = array(
        'Date' => $edit_date,
        'Vehicle' => $plate,
        'Position' => $post,
        'Tread Depth' => $row_sel['tread'],
        'Pressure' => $row_sel['pressure'],
        'Km/Hrs' => $row_sel['kmrun'],
        'Tools' => $tools
        );
        }

       }
       $this->JTTreadWearList->setCellData($grid_arr);
       }


}

global $application;

global $tire_tread_wear_list;

//Creates the form
$tire_tread_wear_list=new tire_tread_wear_list($application);

//Read from resource file
$tire_tread_wear_list->loadResource(__FILE__);

//Shows the form
$tire_tread_wear_list->show();

?>